package com.coder.rental.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coder.rental.entity.CarBrand;
import com.coder.rental.entity.CarMaker;
import com.coder.rental.mapper.CarBrandMapper;
import com.coder.rental.mapper.CarMakerMapper;
import com.coder.rental.service.ICarMakerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 汽车厂商 服务实现类
 * </p>
 *
 * @author zhaojj
 * @since 2025-01-10
 */
@Service
public class CarMakerServiceImpl extends ServiceImpl<CarMakerMapper, CarMaker> implements ICarMakerService {
    @Resource
    private CarBrandMapper carBrandMapper;
    @Override
    public Page<CarMaker> search(int start, int size, CarMaker carMaker) {
        QueryWrapper<CarMaker> queryWrapper = new QueryWrapper<>();
        // 根据名字进行模糊查询
        queryWrapper.orderByAsc("order_letter")
                .like(StrUtil.isNotEmpty(carMaker.getName()), "name", carMaker.getName());
        Page<CarMaker> page = new Page<>(start,size);
        this.page(page,queryWrapper);
        return page;

    }

    @Override
    public boolean hasBrand(Integer makerId) {
        QueryWrapper<CarBrand> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mid",makerId);
        return carBrandMapper.selectCount(queryWrapper) > 0;
    }
}
